package xyz.xtt.equity.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.equity.api.dto.GetBenefitPurchaseRecordRequest;
import xyz.xtt.equity.api.dto.GetOnSaleBenefitPackageRequest;
import xyz.xtt.equity.api.dto.SaveBenefitPurchaseUnPayDto;
import xyz.xtt.equity.api.dto.TblBenefitPackageDto;
import xyz.xtt.equity.api.dto.TblBenefitPurchaseRecordDto;
import xyz.xtt.equity.client.request.GetUnPayBenefitPurchaseRecordRequest;
import xyz.xtt.equity.client.request.HandlePayCancelRequest;
import xyz.xtt.equity.client.request.HandlePaySuccessRequest;
import xyz.xtt.equity.service.INftVipService;
import xyz.xtt.equity.vo.NftVipInfoVo;

/**
 * @author dale
 * @date 2025/2/10
 **/
@Schema(name = "数藏藏会员", description = "数藏藏会员")
@Slf4j
@RestController
@RequestMapping("/api/equity/vip")
@Validated
public class NftVipController {
	@Autowired
	private INftVipService nftVipService;

	@Operation(summary = "会员首页接口")
	@GetMapping("/info")
	public ApiResult<NftVipInfoVo> queryVipInfo(@RequestHeader("uid") Long uid) {
		return ApiResult.ok(nftVipService.queryVipInfo(uid));
	}

	@Operation(summary = "查询单条权益包")
	@PostMapping("/getOnSaleBenefitPackage")
	public ApiResult<TblBenefitPackageDto> getOnSaleBenefitPackage(@RequestBody @Valid GetOnSaleBenefitPackageRequest request) {
		return ApiResult.ok(nftVipService.getOnSaleBenefitPackage(request));
	}

	@Operation(summary = "查询权益包未支付记录")
	@PostMapping("/getUnPayBenefitPurchaseRecord")
	public ApiResult<TblBenefitPurchaseRecordDto> getUnPayBenefitPurchaseRecord(@RequestHeader("uid") Long uid,
			@RequestBody @Valid GetUnPayBenefitPurchaseRecordRequest request) {
		return ApiResult.ok(nftVipService.getUnPayBenefitPurchaseRecord(uid, request));
	}

	@Operation(summary = "保存权益包未支付记录")
	@PostMapping("/saveUnPayBenefitPurchaseRecord")
	public ApiResult<Long> saveUnPayBenefitPurchase(@RequestHeader("uid") Long uid, @RequestBody @Valid SaveBenefitPurchaseUnPayDto saveDto) {
		return ApiResult.ok(nftVipService.saveUnPayBenefitPurchase(uid, saveDto));
	}

	@Operation(summary = "查询权益包支付记录")
	@PostMapping("/getBenefitPurchaseRecord")
	public ApiResult<TblBenefitPurchaseRecordDto> getBenefitPurchaseRecord(@RequestHeader("uid") Long uid,
			@RequestBody @Valid GetBenefitPurchaseRecordRequest request) {
		return ApiResult.ok(nftVipService.getBenefitPurchaseRecord(uid, request));
	}

	@Operation(summary = "支付成功处理")
	@PostMapping("/handlePaySuccess")
	public ApiResult<Boolean> handlePaySuccess(@RequestHeader("uid") Long uid, @RequestBody @Valid HandlePaySuccessRequest request) {
		return ApiResult.ok(nftVipService.handlePaySuccess(uid, request));
	}

	@Operation(summary = "支付取消处理")
	@PostMapping("/handlePayCancel")
	public ApiResult<Boolean> handlePayCancel(@RequestHeader("uid") Long uid, @RequestBody @Valid HandlePayCancelRequest request) {
		return ApiResult.ok(nftVipService.handlePayCancel(uid, request));
	}

}
